-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using ADBKeyboard for injecting text #1751
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR 👍
Ideally, I would like the IME code to be included in scrcpy-server: #37 (comment)
Moreover, this would also allow a socket connection between the server and the IME (to minimize latency).
However, until this is implemented (I have zero time to work on this currently), I think calling ADBkeyboard is an acceptable solution.
If this option is passed, I think it should also save the current IME, set the ADBKeyboard IME, and it should restore the previous one on cleanup.
// Process latin keys the same way in order to provide same reaction speed. | ||
try { | ||
Process process = Runtime.getRuntime().exec("am broadcast -a ADB_INPUT_CHARS --eia chars " + String.valueOf((int) c)); | ||
return process.waitFor() == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should send the broadcast programmatically (to avoid execute a new process and add latency for every letter).
I guess this involves retrieving an IActivityManager
by calling ActivityManager.getService()
(by introspection) (or ActivityManagerNative.getService()
on older versions), and calling broadcastIntent()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that method stable enough? I only have A9 devices and there is something made about activities in A10. I'm not Android developer though.
@@ -651,6 +651,7 @@ guess_record_format(const char *filename) { | |||
#define OPT_DISABLE_SCREENSAVER 1020 | |||
#define OPT_SHORTCUT_MOD 1021 | |||
#define OPT_NO_KEY_REPEAT 1022 | |||
#define OPT_USE_ADB_KEYBOARD 1026 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some numbers don't exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR +1
Ideally, I would like the IME code to be included in scrcpy-server: #37 (comment)
Moreover, this would also allow a socket connection between the server and the IME (to minimize latency).
However, until this is implemented (I have zero time to work on this currently), I think calling ADBkeyboard is an acceptable solution.
If this option is passed, I think it should also save the current IME, set the ADBKeyboard IME, and it should restore the previous one on cleanup.
All of these is right. 👍
https://github.com/Lurker00/scrcpy/releases/tag/v1.10L0 |
Hi, I just implemented what I suggested here, and now it works great (without latency). You could test my work-in-progress branch scrcpy --use-adb-keyboard What remains to do:
|
Hey.
You can just never restore keyboard to ADBKeyboard, that shall solve the
problem.
Kind regards,
Vladimir.
…On Mon, Nov 9, 2020, 11:47 PM Romain Vimont ***@***.***> wrote:
Hi,
I just implemented what I suggested here
<#1751 (comment)>,
and now it works great (without latency).
You could test my work-in-progress branch adbkeyboard
<https://github.com/Genymobile/scrcpy/commits/adbkeyboard>.
scrcpy --use-adb-keyboard
What remains to do:
- automatically select the ADB keyboard on start
- automatically restore the initial keyboard on stop (even if that
won't work if we start 2 instances of scrcpy with ADBKeyboard, since the
second one will consider that the initial keyboard was ADBKeyboard).
- some cleanup
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1751 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARGSB6AQO3LGR3TBX7DUDTSPBIO3ANCNFSM4RFC3LEQ>
.
|
A future next step could be to include the IME in scrcpy (as a real android app), to avoid the requirement to install a separate app. I'm wondering if it's still possible to create a real/installable android app without gradle (using build-tools directly). The reason is that the official debian package uses |
hi, |
@Artur202030 Try with:
|
An issue with using the existing As a consequence, once enabled, any installed app could inject any text or events (anything managed by To avoid the problem, the IME should declare a permission, and with
Note that this may only work for broadcasts, not services or activities. For these cases (or if the solution above does not work), we could require some shell permission. But it will cause issues for XiaoMI devices: Genymobile/gnirehtet#5 (and gnirehtet may not be started by broadcast receivers Genymobile/gnirehtet@f868180). |
Sorry your code works without delay |
Which branch? |
i tested your code and excitoon. Mixed up files. |
Could you confirm that there is no delay on my branch (#1751 (comment))? |
Your code works without delay. |
@excitoon could you please take a look at this PR again? |
@rom1v I have built my self adbkeyboard and used Is there any way to report log? |
@rom1v could you please take a look at this PR? |
@quyleanh I implemented broadcasts so that it works without latency (#1751 (comment)), but the absence of permissions of AdbKeyboard is a problem (#1751 (comment)). Also, scrcpy should enable/disable the keyboard on start/stop. I consider adding a feature to "install" the scrcpy server instead. That way, it could provide its own IME: #1880 (comment)
It should allow to inject any UTF-8 chars (try to copy paste a vietnamese character with Alt+Shift+v to inject characters). |
@rom1v thank you for your kind response.
I know that copy paste feature. But I would like to inject UTF-8 characters directly from keyboard.
So in summary, we will not have inject UTF-8 character directly from keyboard soon? As I understand, there are a lot of problem needed to do. |
Yes, I know, but since you said that Vietnamese characters were not injected, I wanted to check where it failed. There are two copy-paste:
If you use the second method with the ADBKeyboard, I expect that Vietnamese characters work. Is it the case? |
Yes, I use the second method. There are only some Vietnamese characters work. You can refer to this summary table. |
You're not running my branch |
I build your branch and run it now, but I forgot to use |
Try with AdbKeyboard alone: https://github.com/senzhk/ADBKeyBoard (without scrcpy). |
Thank you for your suggestion but I want to use scrcpy for both mirroring screen and injecting text. |
Yes, I got it, but try with AdbKeyboard alone to check if Vietnamese characters work. If they don't, then it's expected that the |
Thank you for your detail instruction. The senzhk/ADBKeyBoard works well. This is my test: adb shell am broadcast -a ADB_INPUT_TEXT --es msg 'Hôm nay trời rất là đẹp. Ồ ngoài kia có chú ngựa ô. Ổ gà. Ở nhà không đi học. Hỏi han. Hello?'
Broadcasting: Intent { act=ADB_INPUT_TEXT flg=0x400000 (has extras) }
Broadcast completed: result=0 Is there any other suggestion? |
Test with ints:
(7891 is 0x1ed3) |
It's fine. The result is |
OK so in theory it should work with scrcpy on |
Actually I have to use an external IME to type and inject Vietnamese on Windows. However other apps are OK with it. By the way, I'm glad to hear that you are working on a work around. Could you please push it in this repo, so I can try it? Or if it needs to test, just let me know. |
@rom1v Using ADBKeyboard to input text is a good solution, which can solve the problem that Samsung and other devices cannot paste text, Why is there no progress? |
I'm using ubuntu 20.04 + fcitx, and I have found 2 problems when using adbkeyboard: |
@rom1v - I was wondering if there is any update on "scrcpy having its its own IME" ? We tried scrcpy on our current stack and even with "--keyboard=uhid" we are still having clipboard paste issue on Samsung devices etc. Switching keyboard inputs on the device is also needed when switching between languages. In the past we have used Vysor with its own IME and that has been a good solution for different language inputs and clipboard management. We are happy to put in work to make this happen if thats something that could be helpful? Maybe getting --use-adb-keyboard into the main release could be one way? Or a custom scrcpy IME apk that can be installed? Thanks for all the work you do. |
No, since most of the need is now covered by UHID keyboard. I understand that there are still issues that UHID keyboard does not solve, but I am not keen on adding a new subproject just for that. Installing AdbKeyboard can also be a problem for security: any app on the device could inject text (#1751 (comment)). |
Yes I understand. Thanks for getting back to me.
I wonder if adding a cli option that would enable a “keyboard broadcaster”,
or something similar, from scrcpy would be something that you might be
willing to add to the core?
Looking at how adbkeyboard was implemented before in the adbkeyboard
branch, we could capture the keyboard inputs and broadcast those, we could
even add a secret key for security that scrcpy could broadcast with the
broadcast and then a custom IME app could listen for those broadcasts. Not
sure if we could add to adbkeyboard but making something similar should be
possible and most likely not too hard.
Let me know what you think, we could look into it more. If it’s something
you would be willing to ado into the core if done correctly we could most
likely put in the work to get it done.
We have looked into using scrcpy in our development and testing stack
before but different language inputs and clipboard management has always
been an issue for us.
…On Mon, Sep 9, 2024 at 16:54 Romain Vimont ***@***.***> wrote:
I was wondering if there is any update on "scrcpy having its its own IME" ?
No, since most of the need is now covered by UHID keyboard.
I understand that there are still issues that UHID keyboard does not
solve, but I am not keen on adding a new subproject just for that.
Installing AdbKeyboard can also be a problem for security: any app on the
device could inject text (#1751 (comment)
<#1751 (comment)>).
—
Reply to this email directly, view it on GitHub
<#1751 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJIUKMTEJ2CVN6LAP6UKFLZVVV4DAVCNFSM6AAAAABN3W7Z6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZXGY3DCNRWGI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Fix compatibility with different languages for 2 years? Are you idiots? |
No description provided.